package com.starblink.android.common.web.deal

import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.toastSuccess
import com.starblink.android.basic.ext.visibleOrGone
import com.starblink.android.common.databinding.ItemWebDealCodeBinding
import com.starblink.basic.util.CommUtils
import com.starblink.rocketreserver.fragment.DealVOF

class WebDealCell(
    binding: ItemWebDealCodeBinding,
    var copyCallback: (() -> Unit)? = null,
) :
    BaseBindingVH<DealVOF, ItemWebDealCodeBinding>(binding = binding) {

    override fun onBind(merchat: DealVOF, position: Int) {
        binding.tvCouponCodeTip.visibleOrGone(!merchat.couponCode.isNullOrEmpty())
        binding.tvCouponCode.visibleOrGone(!merchat.couponCode.isNullOrEmpty()) {
            binding.tvCouponCode.text = "${merchat.couponCode}"
        }
        binding.copy.visibleOrGone(!merchat.couponCode.isNullOrEmpty())
        var pre = if(merchat.discountInfo?.prefix.isNullOrEmpty()) "" else "${merchat.discountInfo?.prefix} "
        var suf = if(merchat.discountInfo?.suffix.isNullOrEmpty()) "" else " ${merchat.discountInfo?.suffix}"
        binding.tvStoreDiscount.text = "$pre${merchat.discountInfo?.discount}$suf"
        binding.copy.setOnClickListener {
            CommUtils.copyText(merchat.couponCode)
            toastSuccess("Copied Successfully!")
            copyCallback?.invoke()
        }
    }
}